home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1047 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.6 KB  |  44 lines

  1. Path: newsfeed.internetmci.com!xmission!news
  2. From: tknarr@xmission.com  ( Todd Knarr )
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: two tricky questions
  5. Date: 9 Jan 1996 02:26:19 GMT
  6. Organization: Chaos Central
  7. Message-ID: <4csjob$gsa@news.xmission.com>
  8. References: <4cnan0$gqv@news.xmission.com> <DKv098.7JE@cix.compulink.co.uk>
  9. Reply-To: tknarr@xmission.com ( Todd Knarr )
  10. NNTP-Posting-Host: slc31.xmission.com
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <DKv098.7JE@cix.compulink.co.uk>, henri@cix.compulink.co.uk ("Henry Andrew") writes:
  14. >It could be that some compilers do it as a bitwise copy but the compiler 
  15. >I am currently using (IBM CSet++ on AIX) does a memberwise copy.
  16. >And in so doing, it seems to me, follow Stroustrup.
  17.  
  18. That's because your class B has a copy constructor defined. Where you
  19. have defined a copy constructor memberwise initialization is possible
  20. and must be done. Bitwise copy occurs when members do not have a copy
  21. constructor.
  22.  
  23. If you want to see it in action, try something like this:
  24.  
  25. void main( void )
  26. {
  27.     A a1, a2;
  28.     a2 = a1;
  29.     cout << a1._b._i << '\t' << a2._b._i << endl;
  30. }
  31.  
  32. Since you didn't define copy assignment for class B, you'll see a
  33. different result ( assuming the compiler doesn't optimize out the
  34. assignment and do it by initialization instead ).
  35.  
  36. --
  37. Todd Knarr : tknarr@xmission.com      |  finger for PGP public key
  38.                                       |  Member, USENET Cabal
  39.  
  40. Seriously, I don't want to die just yet.  I don't care how
  41. good-looking they are, I! don't! want! to! die!"
  42.                                         -- Megazone ( UF1 )
  43.  
  44.